package com.xiaoq.sites.endpoint;

import com.xiaoq.coms.GenericListResponse;
import com.xiaoq.sites.entity.InterDicEntity;
import com.xiaoq.sites.service.IInterDicService;
import com.xiaoq.sites.vo.InterDicVo;
import io.swagger.annotations.*;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/v1/interdic")
@Api(tags = "讲解员相关数据字典")
public class InterDicEndpoint {
	
	@Autowired
	private IInterDicService interDicService;
	
	private class InterDicListResponse extends GenericListResponse<InterDicVo>{}
	
	private static final Logger LOG = LoggerFactory.getLogger(InterDicEndpoint.class);
	
	@ApiOperation(value="讲解员据字典", notes="讲解员数据字典")
	@ApiResponses({
		@ApiResponse(code = 200, response = InterDicListResponse.class, message = "讲解员数据字典")
	})
	@GetMapping(value="", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> lang(
			@RequestParam(value="dicType")
			@ApiParam(value="字典类型(1是 语言   2 是 从业经验)",allowableValues = "1,2", required=true) Integer dicType){

		List<InterDicVo> resultList = new ArrayList<>();
		if(dicType != null){
			List<InterDicEntity> interDicList = interDicService.getAllInterDicList(dicType, null);
			if(CollectionUtils.isNotEmpty(interDicList)){
				InterDicVo interDicVo;
				for(InterDicEntity interDicEntity : interDicList){
					interDicVo = new InterDicVo();
					BeanUtils.copyProperties(interDicEntity, interDicVo);
					resultList.add(interDicVo);
				}
			}
		}
		return InterDicListResponse.listNoCount(resultList);
	}
	

}
